package itheima;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class CalendarTest {
    public static void main(String[] args) {
        SimpleDateFormat abc=new SimpleDateFormat("yyyy-MM-dd");
        //创建一个日历对象
        Calendar calendar = Calendar.getInstance();
        //设置日期
        calendar.set(2022, 9, 1);
        calendar.add(Calendar.MONTH,-3);
        //获取日期
        System.out.println(abc.format(calendar.getTime()));//2022-06-01
//        System.out.print(calendar.get(Calendar.YEAR)+" ");
//        System.out.print(calendar.get(Calendar.MONTH));
//        System.out.print(calendar.get(Calendar.DATE));
        /**
         * public class CalendarTest {
         *     public static void main(String[] args) {
         *         SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
         *         Calendar calendar = Calendar.getInstance();
         *         calendar.set(2025, 9, 11);
         *         calendar.add(Calendar.MONTH,-3);
         *         System.out.println(sdf.format(calendar.getTime()));
         *     }
         * }
         */
    }
}
